package com.zhilianbao.leyaogo.view.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.bql.pulltorefreshandloadmore.loadmoreview.LoadMoreRecyclerView;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.utils.Utils;
import com.zhilianbao.leyaogo.view.decoration.ListItemDecoration;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author: hcy
 * Description:可用卡券，优惠券基类
 * Created: 2016/11/29 19:54
 */
public abstract class BaseCouponDialog extends DialogFragment {

    @BindView(R.id.recycle_view)
    LoadMoreRecyclerView mRecyclerView;
    @BindView(R.id.tv_center)
    TextView mCenterTv;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE,R.style.Dialog);
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = Utils.getScreenWidth();
        lp.height = Utils.dp2px(316);
        lp.windowAnimations = R.style.DialogAnimation;
        lp.gravity = Gravity.BOTTOM;
        window.setAttributes(lp);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.dialog_use_coupon,container);
        ButterKnife.bind(this,view);
        setRecyclerView();

        setData();
        return view;
    }

    abstract void setData();

    abstract String getHeaderText();

    protected void OnConfirmClick(){

    }

    private void setRecyclerView(){
        TextView textView = (TextView) LayoutInflater.from(getActivity()).inflate(R.layout.layout_coupon_dialog_header,null);
        textView.setText(getHeaderText());
        mRecyclerView.addHeaderView(textView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.addItemDecoration(new ListItemDecoration(0));
    }

    @OnClick({R.id.tv_cancel,R.id.tv_confirm})
    public void onClick(View view){
        switch (view.getId()) {
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_confirm:
                OnConfirmClick();
                break;
        }
    }


}
